﻿<Window x:Class="Poet.Views.MainView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:System="clr-namespace:System;assembly=mscorlib" 
        xmlns:Converters="clr-namespace:Poet.Converters"
        Icon="/Avalon;component/../Icons/Rose_32x32.png"
        Title="Poet" Width="966" Height="600"
        WindowStartupLocation="CenterScreen"
        ShowInTaskbar="{Binding ShowInTaskbar}"
        WindowStyle="{Binding WindowStyle}"
        ResizeMode="{Binding ResizeMode}" 
        Topmost="{Binding Topmost}"
        x:Name="this">

    <Window.InputBindings>
        <KeyBinding Key="S" Modifiers="Ctrl+Shift" Command="{Binding SaveAll}"/>
    </Window.InputBindings>

    <Window.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="..\Resources\XamlCollections.xaml" />
            </ResourceDictionary.MergedDictionaries>
    
        <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <Converters:WindowStyleBooleanConverter x:Key="WindowStyleBooleanConverter"/>

        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type System:Enum}" x:Key="WindowStyleValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="WindowStyle" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>

        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type System:Enum}" x:Key="ResizeModeValues">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="ResizeMode" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
            
   </ResourceDictionary>
        
    </Window.Resources>

    <Grid>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Menu 
            IsMainMenu="True"
            Visibility="{Binding ShowMainMenu, Converter={StaticResource BooleanToVisibilityConverter}}"
            Background="{Binding ElementName=ToolBarTray, Path=Background}"
            PreviewMouseDoubleClick="ChangeWindowState"
            PreviewMouseMove="DragMove">

            <Menu.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="..\Resources\MenuResources.xaml" />
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </Menu.Resources>

            <MenuItem Header="{Localizing File}" Name="FileMenu">
                <MenuItem Header="{Localizing New}" Command="{Binding New}" Icon="{Picture Icons/New_16x16.png, 16}"/>
                <MenuItem Header="{Localizing Open}" Command="{Binding Open}" Icon="{Picture Icons/Open_16x16.png, 16}"/>
                <Separator/>
                <MenuItem Header="{Localizing Save}" Command="ApplicationCommands.Save" Icon="{Picture Icons/Save_16x16.png, 16}"/>
                <MenuItem Header="{Localizing SaveAs}" Command="ApplicationCommands.SaveAs"/>
                <MenuItem Header="{Localizing SaveAll}" Command="{Binding SaveAll}" Icon="{Picture Icons/SaveAll_16x16.png, 16}"/>
                <Separator/>
                <MenuItem Header="{Localizing Close}" Command="ApplicationCommands.Close"/>
                <MenuItem Header="{Localizing CloseAll}" Command="{Binding CloseAll}" Icon="{Picture Icons/Close_16x16.png, 16}"/>
                <Separator/>
                <MenuItem Header="{Localizing PageSetup}" Command="PreviousPage" Icon="{Picture Icons/PageSetup_16x16.png, 16}"/>
                <MenuItem Header="{Localizing Print}" Command="ApplicationCommands.Print" Icon="{Picture Icons/Print_16x16.png, 16}"/>
                <Separator/>
                <MenuItem Header="{Localizing Recent}"/>
                <MenuItem Header="{Localizing Pinned}"/>
                <Separator/>
                <MenuItem Header="{Localizing Exit}" Command="{Binding Exit}" Icon="{Picture Icons/Exit_16x16.png, 16}"/>
            </MenuItem>

            <MenuItem Header="{Localizing Edit}" ItemsSource="{StaticResource EditMenuItems}"/>

            <MenuItem Header="{Localizing Content}">
                <MenuItem Header="{Localizing Documents}" Name="DocumentViewsMenuItem" ItemsSource="{Binding DocumentViews}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="IsCheckable" Value="False"/>
                            <Setter Property="IsChecked"  Value="{Binding IsActiveDocument, Mode=OneWay}"/>
                            <Setter Property="Header" Value="{Binding Title}" />
                            <Setter Property="ToolTip" Value="{Binding Path}" />
                            <EventSetter Event="Click" Handler="OnCheckDocumentView"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>
                <MenuItem Header="{Localizing Tools}" ItemsSource="{Binding ToolViews}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="IsCheckable" Value="False"/>
                            <Setter Property="IsChecked"  Value="{Binding IsActiveContent, Mode=OneWay}"/>
                            <Setter Property="Header" Value="{Binding Title}" />
                            <Setter Property="ToolTip" Value="{Binding Title}" />
                            <EventSetter Event="Click" Handler="OnCheckDocumentView"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>

                <Separator/>
                <MenuItem Header="{Localizing Navigator}" InputGestureText="Clrt+Tab" Click="MenuItemClick" Tag="ShowNavigatorWindow"/>
            </MenuItem>

            <MenuItem Header="{Localizing Format}" ItemsSource="{StaticResource FormatMenuItems}"  DataContext="{Binding ActiveDocument.DataContext}"/>
            
            <MenuItem Header="{Localizing View}">
                <MenuItem Header="{Localizing WindowStyle}" Name="WindowStyleMenu"  ItemsSource="{Binding Source={StaticResource WindowStyleValues}}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="IsChecked" Value="{Binding Mode=OneTime, Converter={StaticResource WindowStyleBooleanConverter}}"/>
                            <Setter Property="Header" Value="{Binding}"/>
                            <Setter Property="ToolTip" Value="{Binding}"/>
                            <EventSetter Event="Click" Handler="OnCheckWindowStyle"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>
                <MenuItem Header="{Localizing ResizeMode}" Name="ResizeModeMenu" ItemsSource="{Binding Source={StaticResource ResizeModeValues}}">
                    <MenuItem.ItemContainerStyle>
                        <Style TargetType="{x:Type MenuItem}">
                            <Setter Property="IsChecked" Value="{Binding Mode=OneTime, Converter={StaticResource WindowStyleBooleanConverter}}"/>
                            <Setter Property="Header" Value="{Binding}"/>
                            <Setter Property="ToolTip" Value="{Binding}"/>
                            <EventSetter Event="Click" Handler="OnCheckResizeMode"/>
                        </Style>
                    </MenuItem.ItemContainerStyle>
                </MenuItem>
                <MenuItem Header="{Localizing ToolBars}" ItemsSource="{StaticResource ToolBarTrayMenuItems}"/>
                <MenuItem Header="{Localizing ShowStatusBar}" IsCheckable="True" IsChecked="{Binding ShowStatusBar}"/>
                <MenuItem Header="{Localizing ShowInTaskbar}" IsCheckable="True" IsChecked="{Binding ShowInTaskbar}"/>
                <MenuItem Header="{Localizing ShowInTray}" IsCheckable="True" IsChecked="{Binding ShowInTray}"/>
                <MenuItem Header="{Localizing DisableWindowActivation}" IsCheckable="True" IsChecked="{Binding DisableWindowActivation}"/>
                <MenuItem Header="{Localizing Topmost}" IsCheckable="True" IsChecked="{Binding Topmost}"/>
            </MenuItem>

            <MenuItem Header="{Localizing Help}" ItemsSource="{StaticResource HelpMenuItems}"/>

        </Menu>

        <StackPanel Orientation="Horizontal"  HorizontalAlignment="Right">
            <SimpleToggleButton IsChecked="{Binding Topmost}" ToolTip="{Localizing TopmostToolTip}" Content="{Picture Icons/TopmostOn_16x16.png, 13}" HorizontalAlignment="Right" Margin="2"/>
            <SimpleToggleButton Command="{Binding Exit}" ToolTip="{Localizing TopmostToolTip}" Content="{Picture Icons/PinClose_16x16.png, 13}" HorizontalAlignment="Right" Margin="2"/>
        </StackPanel>

        <ToolBarTray Grid.Row="1" Name="ToolBarTray" MouseDown="DragMove">

            <ToolBarTray.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="..\Resources\MenuResources.xaml" />
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </ToolBarTray.Resources>
            
            <ToolBarTray.ContextMenu>
                <ContextMenu ItemsSource="{StaticResource ToolBarTrayMenuItems}"/>
            </ToolBarTray.ContextMenu>
            
            <ToolBar 
                PreviewGotKeyboardFocus="IgnoreGotKeyboardFocus"
                Visibility="{Binding ElementName=this, Path=DataContext.ShowStandartToolBar, Mode=TwoWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}">

                <Button Command="{Binding New}" Content="{Picture Icons/New_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Button Command="{Binding Open}" Content="{Picture Icons/Open_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Button Command="ApplicationCommands.Save" Content="{Picture Icons/Save_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Button Command="{Binding SaveAll}" Content="{Picture Icons/SaveAll_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Separator/>
                <Button Command="ApplicationCommands.Cut" Content="{Picture Icons/Cut_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Button Command="ApplicationCommands.Copy" Content="{Picture Icons/Copy_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Button Command="ApplicationCommands.Paste" Content="{Picture Icons/Paste_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Button Command="ApplicationCommands.Delete" Content="{Picture Icons/Delete_16x16.png, 16}" ToolTip="{Localizing NewToolTip}"/>
                <Separator/>
                <Button Command="ApplicationCommands.Undo" Content="{Picture Icons/Undo_16x16.png, 16}" ToolTip="{Localizing UndoToolTip}"/>
                <Button Command="ApplicationCommands.Redo" Content="{Picture Icons/Redo_16x16.png, 16}" ToolTip="{Localizing RedoToolTip}"/>

            </ToolBar>

            <ToolBar
                DataContext="{Binding ActiveDocument.TextEditor}" 
                ItemsSource="{StaticResource FormatToolBarItems}"
                PreviewGotKeyboardFocus="IgnoreGotKeyboardFocus"
                Visibility="{Binding ElementName=this, Path=DataContext.ShowFormatToolBar, Mode=TwoWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"/>


            <ToolBar
                DataContext="{Binding ActiveDocument.TextEditor}" 
                ItemsSource="{StaticResource HighlightingToolBarItems}"
                PreviewGotKeyboardFocus="IgnoreGotKeyboardFocus"
                Visibility="{Binding ElementName=this, Path=DataContext.ShowHighlightToolBar, Mode=TwoWay, Converter={StaticResource ResourceKey=BooleanToVisibilityConverter}}"/>

        </ToolBarTray>

        <DockingManager
            Grid.Row="2"
            Name="DockingManager"
            DocumentsSource="{Binding DocumentViews}" 
            ActiveContent="{Binding ActiveContent, Mode=TwoWay}"
            ActiveDocument="{Binding ActiveDocument, Mode=TwoWay}"
            PreviewMouseDoubleClick="DockingManagerPreviewMouseDoubleClick">
            <ResizingPanel>
                <DocumentPane/>
            </ResizingPanel>
        </DockingManager>

        <StatusBar
            Grid.Row="3"   
            PreviewMouseMove="DragMove"
            PreviewMouseDoubleClick="ChangeWindowState"
            ItemsSource="{StaticResource StatusBarItems}"
            DataContext="{Binding ActiveDocument.DataContext}"
            Background="{Binding ElementName=ToolBarTray, Path=Background}"
            Visibility="{Binding ElementName=this, Path=DataContext.ShowStatusBar, Converter={StaticResource BooleanToVisibilityConverter}}"/>
        
    </Grid>
</Window>